﻿@inject IHttpService _httpService
@inject IPopupService PopupService
@inject IEventService _eventService

<MDCard>
    <DataTableCard TModel="BasicInforTableModel" Headers="_headers" ApiUrl="@(_baseUrl)" ShowAddButton="false" Title="@($"{_name}列表")" @ref="dataTableCard">
        <ButtonContent>
            <CnGalWebSite.Shared.MasaComponent.Shared.Buttons.ExportButton OnQueryAsync="@(async ()=>await dataTableCard?.QueryAllAsync())" Name="游戏" Class="me-4" />
        </ButtonContent>

        <ItemColContent>
            @if (context.Header.Value == "actions")
            {
                <MIcon Color="info"
                       Class="mr-2"
                       OnClick="()=>LookItem(context.Item)">@IconType.Look.ToIconString()</MIcon>
            }
            else
            {
                @context.Value
            }
        </ItemColContent>
    </DataTableCard>

</MDCard>



@code {
    private bool _editDialog;
    private long _editedItemId;
    private bool _detailDialog;

    private string _baseUrl = "api/tables/ListGames";
    private string _name = "游戏";

    private List<DataTableHeader<BasicInforTableModel>> _headers = new List<DataTableHeader<BasicInforTableModel>>
    {
        new ()
          {
            Text= "Id",
            Align= DataTableHeaderAlign.Start,
            Value= nameof(BasicInforTableModel.RealId)
          },
          new (){ Text= "名称", Value= nameof(BasicInforTableModel.Name)},
          new (){ Text= "发行时间", Value= nameof(BasicInforTableModel.IssueTime)},
          new (){ Text= "原作", Value= nameof(BasicInforTableModel.Original)},
          new (){ Text= "制作组", Value= nameof(BasicInforTableModel.ProductionGroup)},
          new (){ Text= "游戏平台", Value= nameof(BasicInforTableModel.GamePlatforms)},
          new (){ Text= "引擎", Value= nameof(BasicInforTableModel.Engine)},
          new (){ Text= "发行商", Value= nameof(BasicInforTableModel.Publisher)},
          new (){ Text= "游戏别称", Value= nameof(BasicInforTableModel.GameNickname)},
          new (){ Text= "标签", Value= nameof(BasicInforTableModel.Tags)},
          new (){ Text= "发行方式", Value= nameof(BasicInforTableModel.IssueMethod)},
          new (){ Text= "官网", Value= nameof(BasicInforTableModel.OfficialWebsite)},
          new (){ Text= "Steam平台Id", Value= nameof(BasicInforTableModel.SteamId)},
          new (){ Text= "QQ群", Value= nameof(BasicInforTableModel.QQgroupGame)},
          new (){ Text= "操作", Value= "actions",Sortable=false }
    };

    DataTableCard<BasicInforTableModel> dataTableCard;

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    public async Task LookItem(BasicInforTableModel model)
    {
        await _eventService.OpenNewPage("https://www.cngal.org/entries/index/" + model.RealId);
    }
}
